package com.zdp.netty.chapter6;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * 大小测试
 * @Author zhengdp
 * @Description
 */
public class TestUserInfo {

    public static void main(String[] args) throws IOException {
        UserInfo info = new UserInfo();
        info.buildUserName("Welcome to Netty").buildUserId(100);
        // JDK 序列化
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream os = new ObjectOutputStream(bos);
        os.writeObject(info);
        os.flush();
        os.close();
        byte[] b = bos.toByteArray();
        System.out.println("The jdk serializable length is : " + b.length);
        bos.close();
        System.out.println("------------------------------------------------");
        // 二进制编码
        System.out.println("The byte array serializable length is :" + info.codeC().length);
    }
}
